package com.atguigu.ssyx.activity.service.impl;

import com.atguigu.ssyx.model.activity.Seckill;
import com.atguigu.ssyx.vo.activity.SeckillQueryVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.atguigu.ssyx.activity.service.SeckillService;
import com.atguigu.ssyx.activity.mapper.SeckillMapper;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @author LiJun
 * @description 针对表【seckill(秒杀活动)】的数据库操作Service实现
 * @createDate 2025-05-11 20:52:31
 */
@Service
public class SeckillServiceImpl extends ServiceImpl<SeckillMapper, Seckill>
        implements SeckillService {

    @Override
    public void updateStatus(Long id, Integer status) {
        Seckill seckill = new Seckill();
        seckill.setId(id);
        seckill.setStatus(status);
        this.updateById(seckill);
    }

    @Override
    public IPage<Seckill> selectPage(Page<Seckill> pageParam, SeckillQueryVo seckillQueryVo) {
        LambdaQueryWrapper<Seckill> wrapper = new LambdaQueryWrapper<>();
        String title = seckillQueryVo.getTitle();
        Integer status = seckillQueryVo.getStatus();
        if (StringUtils.hasText(title)) {
            wrapper.like(Seckill::getTitle, title);
        }
        if (status != null) {
            wrapper.eq(Seckill::getStatus, status);
        }
        return baseMapper.selectPage(pageParam, wrapper);
    }
}




